%main = centerCoords(main)
%   This function centers the coordinates of all elements in 'main' around
%   [0,0] by calculating the "center of mass" (with the mass of every atom
%   to be equal, since we want the middle of the coordinates, not the
%   actual center of mass) and then translating the coordinates.

%%

function main = centerCoords(main)
% This function allows us to print the molecule on the center of the screen
% The function returns the new coordinates in main.

%% Initialising
%Getting the length, the average x and average y.
n = length(main);
x = sum([main.x])/n; %Calculates avg.
y = sum([main.y])/n; %Calculates avg.

%% Main
for j = 1:n %Centers all x-coordinates around the avg
    main(j).x = main(j).x - x; 
    main(j).y = main(j).y - y;
end

end